// HookMenuWnd.cpp: implementation of the CHookMenuWnd class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"
#include "HookMenuWnd.h"


#include "ODMenu.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CHookMenuWnd::CHookMenuWnd()
{

}

CHookMenuWnd::~CHookMenuWnd()
{

}
LRESULT CHookMenuWnd::WindowProc( UINT uMsg, WPARAM wParam, LPARAM lParam )
{
	AFX_MANAGE_STATE(AfxGetStaticModuleState())


	switch(uMsg)
	{
	case WM_NCLBUTTONDOWN:
	case WM_NCRBUTTONDOWN:
		{
			if(wParam == HTSYSMENU)
			{
				CWnd * pWnd = CWnd::FromHandle(m_hWnd);
				CMenu SysMenu;
				HMENU hSysMenu = GetSystemMenu(m_hWnd, FALSE);
				SysMenu.Attach( hSysMenu );
				
				if(SysMenu.m_hMenu==NULL)
					return FALSE;
				CPoint point(LOWORD(lParam), HIWORD(lParam));
				SysMenu.TrackPopupMenu( 0, point.x, point.y, pWnd  );		
				SysMenu.Detach();
				return 0;
			}
			else 
				break;
		}
		case WM_INITMENUPOPUP:
			{
				HMENU	hmenuPopup = (HMENU) wParam; 
				UINT	uPos = (UINT)LOWORD(lParam); 
				BOOL	fSystemMenu = (BOOL)HIWORD(lParam);
				CODMenu::OnInitMenuPopup(CMenu::FromHandle(hmenuPopup),uPos,fSystemMenu);
			}
			break;
		case WM_MEASUREITEM:
			{
				int nIDCtl = wParam;
				LPMEASUREITEMSTRUCT lpMeasureItemStruct = (LPMEASUREITEMSTRUCT)lParam;
				if(nIDCtl==0)
				{
					CODMenu::OnMeasureItem(nIDCtl,lpMeasureItemStruct);
				}
			}
			break;
		case WM_DRAWITEM:
			{
				int nIDCtl = wParam;
				LPDRAWITEMSTRUCT lpDrawItemStruct = (LPDRAWITEMSTRUCT)lParam;
				if(nIDCtl==0)
				{
					CODMenu::OnDrawItem(nIDCtl,lpDrawItemStruct);
				}
			}break;
		case WM_COMMAND:
			{
				WORD hw = HIWORD(wParam);
				WORD lw = LOWORD(wParam);
				WORD controlHandle = (WORD)lParam;
				if(hw == 0 && controlHandle==0)
				{
					CString szMenuInfo;
					szMenuInfo.Format("Menu ID : %d",lw);
					//		AfxMessageBox(szMenuInfo);
					TRACE("Trace %s\n",szMenuInfo);
				}else if(controlHandle!=0)
				{
					CString szMenuInfo;
					szMenuInfo.Format("Button ID : %d",lw);
					//		AfxMessageBox(szMenuInfo);
					TRACE("Trace %s\n",szMenuInfo);
				}
			}
			break;
	}
	return CallWindowProc(m_pOldWndProc,m_hWnd,uMsg,wParam,lParam);
}
